package com.htiiot.base;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.log4j.Logger;

import java.io.IOException;

public class EndHook implements Runnable {
    private static Logger log = Logger.getLogger(EndHook.class);
    private FSDataOutputStream[] streams;

    public EndHook(FSDataOutputStream ... streams){
        this.streams = streams;
    }

    @Override
    public void run() {
        log.info("Application quit!Start execute hook...");
        for(int i=0;i<streams.length;i++){
            if(streams[i]!=null){
                try {
                    streams[i].close();
                } catch (IOException e) {
                    log.error(e);
                    e.printStackTrace();
                }
            }
        }
        log.info("BYE!");
    }
}
